﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace device_query_tool
{
    // device 排序器，以 ip 为关键字排序 
    public class DeviceSorter : IComparer
    {
        public int Compare(object x, object y)
        {
            TreeNode tx = x as TreeNode;
            TreeNode ty = y as TreeNode;

            String[] txValue = tx.Text.Split('.');
            String[] tyValue = ty.Text.Split('.');
            txValue[3] = txValue[3].Split('-')[0];
            tyValue[3] = tyValue[3].Split('-')[0];
            for (int i = 0; i < 4; i++)
            {
                if (Convert.ToInt32(txValue[i]) > Convert.ToInt32(tyValue[i]))
                {
                    return 1;
                }
                else if (Convert.ToInt32(txValue[i]) < Convert.ToInt32(tyValue[i]))
                {
                    return -1;
                }
            }
            return 0;
        }
    }
}
